<?php
namespace Admin\Controller;
use Think\Controller;
//2017——1——25加===后台管理评论
class CommonController extends Controller {
        //展示用户评论
        public function index(){
            //实例化评论表，用户表，商品表
            $comment = M('comment');
            $goods = M('goods');
            $user = M('user');
            $list = $comment->select();
            // dump($list);
            $num = count($list);
            for ($i=0; $i < $num; $i++) { 
                //设置查询user表条件
                $map['id'] = ['eq',$list[$i]['uid']];
                //查询用户表
                $ulist = $user->where($map)->find();
                $list[$i]['username'] = $ulist['username'];
                $map = [];
                $map['id'] = ['eq',$list[$i]['gid']];
                //查询goods表
                $glist = $goods->where($map)->find();
                $list[$i]['goodsname'] = $glist['goods'];
                $list[$i]['goodspic'] = $glist['pic'];
            }
            $this->assign('list',$list);
            $this->display();
        }
        //删除操作
        public function del_comment(){
            //获取id
            $id = I('id');
            //实例化 comment表
            $comment = M('comment');
            //设置删除条件
            $map['id'] = ['eq',$id];
            $res = $comment->where($map)->delete();
            if($res){
                echo '删除成功';
            }else{
                echo '删除失败';
            }
        }
   
}